package com.leetcode.partition3;

/**
 * @author `RKC`
 * @date 2021/11/8 12:03
 */
public class LC299猜数字游戏 {

    public String getHint(String secret, String guess) {
        int x = 0, y = 0;
        int[] cnt = new int[10];
        for (int i = 0; i < secret.length(); i++) {
            cnt[secret.charAt(i) - '0']++;
        }
        for (int i = 0; i < secret.length(); i++) {
            char c1 = secret.charAt(i), c2 = guess.charAt(i);
            if (c1 == c2) {
                x++;
                cnt[c1 - '0']--;
            }
        }
        for (int i = 0; i < secret.length(); i++) {
            char c1 = secret.charAt(i), c2 = guess.charAt(i);
            if (c1 != c2 && cnt[c2 - '0'] > 0) {
                y++;
                cnt[c2 - '0']--;
            }
        }
        return x + "A" + y + "B";
    }
}
